package com.salley.controller;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "Session",description = "Spring session")
@RequestMapping("/session")
@RestController
public class SessionController {
	
	@ApiOperation(value = "redis实现sessiong 共享")
	@RequestMapping("/redis")
	public String redis(String browser,HttpServletRequest request,HttpSession session) {
		Object attribute = session.getAttribute("browser");
		String id = session.getId();
		if ( attribute == null) {
			session.setAttribute("browser", browser);

			System.out.println("session 中无browser" + "---" + id);
		} else {
			System.out.println("session 中有browser，sessionId:" + id);
		}
		Cookie[] cookies = request.getCookies();
		for (Cookie cookie : cookies) {
			System.out.println(cookie.getName() + "= " + cookie.getValue());
		}
		return browser ;
	}
}
